<template>
  <div>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td>病房号</td>
          <td><input type="text" v-model="info.bname" /></td>
        </tr>
        <tr>
          <td>科室</td>
          <td>
            <select v-model="info.kid">
              <option value="">请选择</option>
              <option v-for="a in date.list" :value="a.kid">
                {{ a.kname }}
              </option>
            </select>
          </td>
        </tr>
        <tr>
          <td>床位总数量</td>
          <td><input type="number" v-model="info.bnum" /></td>
        </tr>
        <tr>
          <td>空闲床数量</td>
          <td><input type="number" v-model="info.bnums" /></td>
        </tr>
        <tr>
          <td></td>
          <td><input type="button" value="添加" @click="Add" /></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { reactive, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import moment from "moment";
const route = useRoute();
const router = useRouter();
let info: any = reactive({
  bname: "",
  kid: "",
  bnum: 0,
  btype: 1,
  bnums: 0,
});
let date: any = reactive({
  list: [],
});
onMounted(() => {
  Find();
});
const Find = () => {
  axios({
    url: "/api/Yesheng/Find",
    method: "get",
  }).then((res) => {
    console.log(res);
    date.list = res.data;
  });
};

const Add = () => {
  if (info.bname == "" || info.bname.length > 6) {
    alert("病房名称不能为空且不能超过6个字符");
    return;
  }
  axios({
    url: "/api/Bingfang/Add",
    method: "post",
    data: info,
  }).then((res) => {
    if (res.data > 0) {
      alert("添加成功");
      router.push("/listbingfang");
      return;
    } else {
      alert("添加失败");
      return;
    }
  });
};
</script>

<style scoped></style>
